package reflect;

import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Person p = new Person();
        System.out.println(p);

        //Class c = Person.class;

        //Class c = Class.forName("reflect.Person");
        /*
        reflect.Person   //包名。类名
        java.util.ArrayList
        java.util.HashMap
        java.util.Data
         */

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入类名");
        String className = scan.next();
        Class c = Class.forName(className);
        /*
        Class的newInstance()方法，只能使用无参构造器进行实例化
         */
        Object obj  = c.newInstance();
        System.out.println(obj);
    }
}
